<template>
	<div>
		<el-form :model="formData" ref="formRef" :rules="formRules" label-width="7rem">
			<el-row type="flex" :gutter="10">
				<el-col :span="12">
					<el-form-item prop="seck_start_time" label="秒杀开始时间">
						<el-date-picker clearable v-model="formData.seck_start_time" value-format="yyyy-MM-dd hh:mm:ss" size="mini"
							type="datetime" placeholder="选择秒杀开始时间">
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item prop="seck_end_time" label="秒杀结束时间">
						<el-date-picker clearable v-model="formData.seck_end_time" value-format="yyyy-MM-dd hh:mm:ss" size="mini"
							type="datetime" placeholder="选择秒杀结束时间">
						</el-date-picker>
					</el-form-item>
				</el-col>
			</el-row>
			<el-table :data="killlist" style="width: 100%">
				<!-- <el-table-column prop="goods_price" label="规格名"></el-table-column> -->
				<el-table-column prop="goods_price" label="原价"></el-table-column>
				<el-table-column prop="newprice" label="秒杀价">
					<template slot-scope="{row}">
						<el-input-number style="width: 200px;" :min="0" :precision="2" :step="0.1" v-model="row.newprice" placeholder="请输入秒杀价"></el-input-number>
					</template>
				</el-table-column>
			</el-table>
			<el-row type="flex" justify="center" style="margin-top: 20px;">
							<el-button type="primary" icon="el-icon-check" @click="sumbit">提交</el-button>
							<el-button type="default" icon="el-icon-close" @click="onCancel">取消</el-button>
						</el-row>
		</el-form>
		
	</div>
</template>

<script>
	import {
		get,post,
		del, imghttp
	} from "@/assets/js/http.js";
	export default {
		props: {
			killlist: {
				type: Array,
				default: () => []
			},
			id:{
				type: Number,
				default: () => 0
			}
		},
		data() {
			return {
				formData: {
					seck_start_time: '',
					seck_end_time: ''
				},
				specs:[],
				formRules: {
					seck_start_time: [{
						required: true,
						message: '必填',
						trigger: 'blur'
					}],
					seck_end_time: [{
						required: true,
						message: '必填',
						trigger: 'blur'
					}],
				},
			}
		},
		methods: {
			sumbit(){
				this.$refs.formRef.validate((valid) => {
					if (valid) {
						this.killlist.forEach(item=>{
							this.specs.push({
								id:item.id,
								goods_price:item.newprice||item.goods_price,
							})
						})
						console.log(this.formData,this.specs)
						post({
							url:'/admin/shop.goods/setSeck',
							data:{
								...this.formData,
								specs:this.specs,
								id:this.id
							},
							successTip: true,
						})
						this.$emit("update");
						this.$parent.$emit("update:visible", false);
						this.$refs.formRef.resetFields()
					} else {
						console.log('error submit!!');
						return false;
					}
				});
			},
			onCancel() {
				this.$parent.$emit("update:visible", false);
				this.$refs.formRef.resetFields();
			}

		}
	}
</script>

<style>
</style>